package io.finer.erp.jeecg.stock.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.UUID;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.api.client.util.Lists;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
import io.finer.erp.jeecg.bas.dto.FqDTO;
import io.finer.erp.jeecg.bas.entity.*;
import io.finer.erp.jeecg.bas.service.*;
import io.finer.erp.jeecg.bas.vo.PrintOrderVO;
import io.finer.erp.jeecg.jolimark.enums.FileTypeEnum;
import io.finer.erp.jeecg.jolimark.enums.PrinterEnum;
import io.finer.erp.jeecg.jolimark.print.FilePrint;
import io.finer.erp.jeecg.stock.entity.ChangeStoreInventory;
import io.finer.erp.jeecg.stock.entity.StkInventory;
import io.finer.erp.jeecg.stock.entity.StkIoBill;
import io.finer.erp.jeecg.stock.entity.StkIoBillEntry;
import io.finer.erp.jeecg.stock.mapper.StkInventoryMapper;
import io.finer.erp.jeecg.stock.service.IStkInventoryService;
import io.finer.erp.jeecg.stock.service.IStkIoBillService;
import net.sf.jxls.transformer.XLSTransformer;
import org.jeecg.common.constant.StoreConstant;
import org.jeecg.common.constant.WarehouseConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.RestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;

/**
 * @Description: 库存
 * @Author: jeecg-boot
 * @Date:   2020-04-11
 * @Version: V1.0
 */
@Service
public class StkInventoryServiceImpl extends ServiceImpl<StkInventoryMapper, StkInventory> implements IStkInventoryService {
    @Autowired
    StkInventoryMapper stkInventoryMapper;
    @Autowired
    IBasMaterialService basMaterialService;
    @Autowired
    IBasMeasureUnitService basMeasureUnitService;
    @Autowired
    private IBasMaterialCategoryService categoryService;
    @Autowired
    private IBasSupplierService supplierService;
    @Autowired
	private IZrkDeliverEntryService zrkDeliverEntryService;
    @Autowired
	private IStkIoBillService stkIoBillService;
    @Autowired
	private IZrkShoporderService shoporderService;
    @Autowired
    private IZrkOrderProductService orderProductService;

	private final FilePrint filePrint = new FilePrint();

    @Override
    @Transactional
    public void increase(StkIoBillEntry stkIoBillEntry) {
        StkInventory inv_new = new StkInventory();
        inv_new.setWarehouseId(stkIoBillEntry.getWarehouseId());
        inv_new.setMaterialId(stkIoBillEntry.getMaterialId());
        inv_new.setBatchNo(stkIoBillEntry.getBatchNo());

        QueryWrapper<StkInventory> queryWrapper = new QueryWrapper<StkInventory>(inv_new);
        StkInventory inv = stkInventoryMapper.selectOne(queryWrapper);
        String supplierId = stkIoBillEntry.getSupplierId();
        if (inv == null) {
            BasMaterial basMaterial = basMaterialService.getById(stkIoBillEntry.getMaterialId());
            if (basMaterial == null) {
                throw new JeecgBootException(String.format("【分录号：%s】物料在物料表中不存在！",
                        stkIoBillEntry.getEntryNo()));
            }

            inv_new.setUnitId(stkIoBillEntry.getUnitId());
            if (stkIoBillEntry.getBatchNo().equals("0") || supplierId == null || supplierId.isEmpty()) {
                inv_new.setIsSingleSupplier(0);
            }
            else {
                inv_new.setIsSingleSupplier(1);
            }
            inv_new.setSupplierId(supplierId);
            //如果供应商不存在则赋值物料分类里的供应商
            BasSupplier supplier = supplierService.getById(supplierId);
            if(supplier == null) {
            	String materialId = stkIoBillEntry.getMaterialId();
            	BasMaterial material = this.basMaterialService.getById(materialId);
            	if(null != materialId) {
            		String categoryId = material.getCategoryId();
            		BasMaterialCategory category = this.categoryService.getById(categoryId);
            		if(null != category) {
            			inv_new.setSupplierId(category.getSupplierId());
            		}
            	}
            }

            if (stkIoBillEntry.getUnitId().equals(basMaterial.getUnitId())) {
                inv_new.setQty(stkIoBillEntry.getQty());
            } else {
                BigDecimal rate = basMeasureUnitService.getRate(basMaterial.getUnitId(),
                        stkIoBillEntry.getUnitId());
                inv_new.setUnitId(basMaterial.getUnitId());
                inv_new.setQty(stkIoBillEntry.getQty().multiply(rate));
            }

            inv_new.setCost(stkIoBillEntry.getCost());
            if(inv_new.getCost() == null) {
            	inv_new.setCost(BigDecimal.ZERO);
            }
            stkInventoryMapper.insert(inv_new);
        } else {
            if (inv.getIsSingleSupplier() == 1 && !inv.getSupplierId().equals(supplierId)) {
                throw new JeecgBootException(String.format("【分录号：%s】供应商与实时库存中“仓库+物料+批次号”的供应商不同！",
                        stkIoBillEntry.getEntryNo()));
            }

            if (supplierId != null && !supplierId.isEmpty()) {
                inv.setSupplierId(supplierId); //保存该批次最后一次入库的供应商
            }

            if (stkIoBillEntry.getUnitId().equals(inv.getUnitId())) {
                inv.setQty(inv.getQty().add(stkIoBillEntry.getQty()));
            }
            else {
                BigDecimal rate = basMeasureUnitService.getRate(inv.getUnitId(),
                        stkIoBillEntry.getUnitId());
                inv.setQty(inv.getQty().add(stkIoBillEntry.getQty().multiply(rate)));
            }
            if (inv.getQty().compareTo(BigDecimal.ZERO) < 0) {
                throw new JeecgBootException(String.format("【分录号：%s】“仓库+物料+批次号”的库存数不足！",
                        stkIoBillEntry.getEntryNo()));
            }

            inv.setCost(inv.getCost().add(stkIoBillEntry.getCost()));
            stkInventoryMapper.updateById(inv);
        }
    }
    
    public void updateProductInCost(StkIoBillEntry stkIoBillEntry) {
    	LambdaQueryWrapper<StkInventory> inventoryQuery = new LambdaQueryWrapper<>();
    	inventoryQuery.eq(StkInventory::getMaterialId, stkIoBillEntry.getMaterialId());
    	inventoryQuery.eq(StkInventory::getWarehouseId, stkIoBillEntry.getWarehouseId());
    	List<StkInventory> list = list(inventoryQuery);
    	if(null != list && list.size() != 0) {
    		StkInventory inventory = list.get(0);
    		inventory.setCost(stkIoBillEntry.getCost());
    		this.stkInventoryMapper.updateById(inventory);
    	}
    }

    @Override
    @Transactional
    public void decrease(StkIoBillEntry stkIoBillEntry) {
        StkInventory inv_new = new StkInventory();
        inv_new.setWarehouseId(stkIoBillEntry.getWarehouseId());
        inv_new.setMaterialId(stkIoBillEntry.getMaterialId());
        inv_new.setBatchNo(stkIoBillEntry.getBatchNo());

        QueryWrapper<StkInventory> queryWrapper = new QueryWrapper<StkInventory>(inv_new);
        StkInventory inv = stkInventoryMapper.selectOne(queryWrapper);
        if (inv == null) {
            throw new JeecgBootException(String.format("【分录号：%s】“仓库+物料+批次号”在实时库存中不存在！",
                    stkIoBillEntry.getEntryNo()));
        }
        if (stkIoBillEntry.getUnitId().equals(inv.getUnitId())) {
            inv.setQty(inv.getQty().subtract(stkIoBillEntry.getQty()));
        }
        else {
            BigDecimal rate = basMeasureUnitService.getRate(inv.getUnitId(),
                    stkIoBillEntry.getUnitId());
            inv.setQty(inv.getQty().subtract(stkIoBillEntry.getQty().multiply(rate)));
        }
        if (inv.getQty().compareTo(BigDecimal.ZERO) < 0) {
            throw new JeecgBootException(String.format("【分录号：%s】“仓库+物料+批次号”的库存数不足！",
                    stkIoBillEntry.getEntryNo()));
        }

        inv.setCost(inv.getCost().subtract(stkIoBillEntry.getCost()));
        stkInventoryMapper.updateById(inv);
    }
    
	@Override
	@Transactional
	public void newDecrease(StkIoBillEntry stkIoBillEntry) {
		// TODO Auto-generated method stub
		LambdaQueryWrapper<StkInventory> query = new LambdaQueryWrapper<>();
		query.eq(StkInventory::getMaterialId, stkIoBillEntry.getMaterialId());
		query.eq(StkInventory::getWarehouseId, stkIoBillEntry.getWarehouseId());
		query.gt(StkInventory::getQty, BigDecimal.ZERO);
		
		List<StkInventory> list = this.list(query);
		if(CollUtil.isEmpty(list)) {
			throw new JeecgBootException(String.format("“仓库+物料”且数量大于0的记录在实时库存中不存在！",
                    stkIoBillEntry.getEntryNo()));
		}
		
		StkInventory inv = list.get(0);
		if (stkIoBillEntry.getUnitId().equals(inv.getUnitId())) {
            inv.setQty(inv.getQty().subtract(stkIoBillEntry.getQty()));
        }
        else {
            BigDecimal rate = basMeasureUnitService.getRate(inv.getUnitId(),
                    stkIoBillEntry.getUnitId());
            inv.setQty(inv.getQty().subtract(stkIoBillEntry.getQty().multiply(rate)));
        }
        if (inv.getQty().compareTo(BigDecimal.ZERO) < 0) {
            throw new JeecgBootException(String.format("【分录号：%s】“仓库+物料+批次号”的库存数不足！",
                    stkIoBillEntry.getEntryNo()));
        }

        inv.setCost(inv.getCost().subtract(stkIoBillEntry.getCost()));
        stkInventoryMapper.updateById(inv);
	}

    @Override
    @Transactional
    public void changeCost(StkIoBillEntry stkIoBillEntry) {
        StkInventory inv_new = new StkInventory();
        inv_new.setWarehouseId(stkIoBillEntry.getWarehouseId());
        inv_new.setMaterialId(stkIoBillEntry.getMaterialId());
        inv_new.setBatchNo(stkIoBillEntry.getBatchNo());

        QueryWrapper<StkInventory> queryWrapper = new QueryWrapper<StkInventory>(inv_new);
        StkInventory inv = stkInventoryMapper.selectOne(queryWrapper);
        if (inv == null) {
            throw new JeecgBootException(String.format("【分录号：%s】“仓库+物料+批次号”在实时库存中不存在！",
                    stkIoBillEntry.getEntryNo()));
        }

        BigDecimal cost = inv.getCost().add(stkIoBillEntry.getCost());
        if (cost.compareTo(BigDecimal.ZERO) < 0) {
            throw new JeecgBootException(String.format("【分录号：%s】“仓库+物料+批次号”调整后成本不能为负！",
                    stkIoBillEntry.getEntryNo()));
        }

        inv.setCost(cost);
        stkInventoryMapper.updateById(inv);
    }

    @Override
    public StkInventory getByBatchNoAndX(String batchNo, String materialId, String warehouseId) {
        StkInventory inv = new StkInventory();
        inv.setBatchNo(batchNo);
        inv.setMaterialId(materialId);
        inv.setWarehouseId(warehouseId);
        QueryWrapper<StkInventory> queryWrapper = new QueryWrapper<StkInventory>(inv);
        return stkInventoryMapper.selectOne(queryWrapper);
    }
    
	@Override
	public StkInventory getByMaterial(String materialId) {
		LambdaQueryWrapper<StkInventory> q = new LambdaQueryWrapper<>();
		q.eq(StkInventory::getMaterialId, materialId);
		q.orderByDesc(StkInventory::getCreateTime);
		q.gt(StkInventory::getQty, BigDecimal.ZERO);
		List<StkInventory> list = this.list(q);
		if (null != list && 0 < list.size()) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public boolean changeStoreInventory(List<String> materialIds) {
		List<BasMaterialCategory> productCategorys = this.categoryService.getChildCategory("1296737703785730050");
		List<String> cateGoryIds = new ArrayList<>();
		for (BasMaterialCategory cate : productCategorys) {
			cateGoryIds.add(cate.getId());
		}
		LambdaQueryWrapper<BasMaterial> mq = new LambdaQueryWrapper<>();
		mq.in(BasMaterial::getId, materialIds);
		mq.in(BasMaterial::getCategoryId, cateGoryIds);
		mq.orderByAsc(BasMaterial::getName);
		List<BasMaterial> mList = this.basMaterialService.list(mq);
		if(null == mList || 0 == mList.size()) {
			return false;
		}
		List<String> queryMaterial = new ArrayList<>();
		queryMaterial.add(UUID.randomUUID().toString());
		
		for (BasMaterial basMaterial : mList) {
			queryMaterial.add(basMaterial.getId());
		}
		List<ChangeStoreInventory> csis = this.baseMapper.getInventoryOrderByName(queryMaterial);
		if(null == csis || 0 == csis.size()) {
			return false;
		}
		Map<String, List<ChangeStoreInventory>> map = new LinkedHashMap<>();
		for (ChangeStoreInventory csi : csis) {
			List<ChangeStoreInventory> list = map.get(csi.getMaterialName());
			if (null == list) {
				list = new ArrayList<>();
				map.put(csi.getMaterialName(), list);
			}
			list.add(csi);
		}
		List<ChangeStoreInventory> result = new ArrayList<>();
		for (String name : map.keySet()) {
			List<ChangeStoreInventory> list = map.get(name);
			BigDecimal stock = BigDecimal.ZERO;
			for (ChangeStoreInventory changeStoreInventory : list) {
				if(null != changeStoreInventory.getStock()) {
					stock = stock.add(changeStoreInventory.getStock());
				}
			}
			for (ChangeStoreInventory changeStoreInventory : list) {
				changeStoreInventory.setStock(stock);
			}
			result.addAll(list);
		}
		String str = JSONObject.toJSONString(result);
		System.out.println(str);
		JSONObject object = new JSONObject();
		object.put("materials", str);
		JSONObject resultObject = RestUtil.post(StoreConstant.STORE_URL + "goods/sku/updateKC", object);
		System.out.println(resultObject.toJSONString());
		return true;
	}

	@Override
	public List<FqDTO> getFqParameter(BigDecimal width, BigDecimal length, String categoryId) {
		return this.baseMapper.getFqParameter(width, length, categoryId);
	}

	@Override
	public StkInventory selectByWarehouseAndMaterial(String warehouseId, String materialId) {
		LambdaQueryWrapper<StkInventory> query = new LambdaQueryWrapper<>();
		query.eq(StkInventory::getWarehouseId, warehouseId);
		query.eq(StkInventory::getMaterialId, materialId);
		List<StkInventory> list = list(query);
		if(list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<StkInventory> selectByMaterials(List<String> materialIds) {
		List<StkInventory> list = this.baseMapper.selectByMaterials(materialIds);
		return list;
	}

	@Override
	public StkInventory selectLatestByMaterial(String id) {
		LambdaQueryWrapper<StkInventory> query = new LambdaQueryWrapper<>();
		query.eq(StkInventory::getMaterialId, id);
		query.orderByDesc(StkInventory::getCreateTime);
		List<StkInventory> list = this.list(query);
		if(list != null && list.size() != 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<StkInventory> getInventoryCategoryByMaterialId(String materialId) {
		// TODO Auto-generated method stub
		BasMaterial material = this.basMaterialService.getById(materialId);
		List<String> ids = this.basMaterialService.getInventoryMaterialIdsByCategory(material.getCategoryId());
		LambdaQueryWrapper<StkInventory> query = new LambdaQueryWrapper<>();
		query.in(StkInventory::getMaterialId, ids);
		return list(query);
	}

	@Override
	public BigDecimal getCPQtyByMaterialId(String materialId) {
		List<StkInventory> inventorys = this.getInventoryCategoryByMaterialId(materialId);
		if(null != inventorys && 0 != inventorys.size()) {
			List<String> ids = Lists.newArrayList();
			ids.add(UUID.randomUUID().toString());
			for (StkInventory stkInventory : inventorys) {
				if(WarehouseConstant.CPK_ID.equals(stkInventory.getWarehouseId())) {
					ids.add(stkInventory.getId());
				}
			}
			QueryWrapper<StkInventory> as = new QueryWrapper<StkInventory>();
			as.select("ifnull(sum(qty),0) as total ");
			as.in("id", ids);
			Map<String, Object> result = this.getMap(as);
			BigDecimal number = new BigDecimal(String.valueOf(result.get("total")));
			return number;
		}
		return null;
	}

	@Override
	public BigDecimal getBCPQtyByMaterialId(String materialId) {
		List<StkInventory> inventorys = this.getInventoryCategoryByMaterialId(materialId);
		if(null != inventorys && 0 != inventorys.size()) {
			List<String> ids = Lists.newArrayList();
			ids.add(UUID.randomUUID().toString());
			for (StkInventory stkInventory : inventorys) {
				if(!WarehouseConstant.CPK_ID.equals(stkInventory.getWarehouseId())) {
					ids.add(stkInventory.getId());
				}
			}
			QueryWrapper<StkInventory> as = new QueryWrapper<StkInventory>();
			as.select("ifnull(sum(qty),0) as total ");
			as.in("id", ids);
			Map<String, Object> result = this.getMap(as);
			BigDecimal number = new BigDecimal(String.valueOf(result.get("total")));
			return number;
		}
		return null;
	}

	@Override
	public BigDecimal getCPQtyByCategoryId(String categoryId) {
		List<StkInventory> inventorys = this.getInventoryByCategory(categoryId);
		if(inventorys != null && inventorys.size() > 0) {
			List<String> ids = Lists.newArrayList();
			ids.add(UUID.randomUUID().toString());
			for (StkInventory stkInventory : inventorys) {
				if(WarehouseConstant.CPK_ID.equals(stkInventory.getWarehouseId())) {
					ids.add(stkInventory.getId());
				}
			}
			QueryWrapper<StkInventory> as = new QueryWrapper<StkInventory>();
			as.select("ifnull(sum(qty),0) as total ");
			as.in("id", ids);
			Map<String, Object> result = this.getMap(as);
			BigDecimal number = new BigDecimal(String.valueOf(result.get("total")));
			return number;
		}
		return null;
	}

	@Override
	public BigDecimal getBCPQtyByCategoryId(String categoryId) {
		List<StkInventory> inventorys = this.getInventoryByCategory(categoryId);
		if(inventorys != null && inventorys.size() > 0) {
			List<String> ids = Lists.newArrayList();
			ids.add(UUID.randomUUID().toString());
			for (StkInventory stkInventory : inventorys) {
				if(!WarehouseConstant.CPK_ID.equals(stkInventory.getWarehouseId())) {
					ids.add(stkInventory.getId());
				}
			}
			QueryWrapper<StkInventory> as = new QueryWrapper<StkInventory>();
			as.select("ifnull(sum(qty),0) as total ");
			as.in("id", ids);
			Map<String, Object> result = this.getMap(as);
			BigDecimal number = new BigDecimal(String.valueOf(result.get("total")));
			return number;
		}
		return null;
	}
	
	public List<StkInventory> getInventoryByCategory(String categoryId) {
		List<String> ids = this.basMaterialService.getInventoryMaterialIdsByCategory(categoryId);
		LambdaQueryWrapper<StkInventory> query = new LambdaQueryWrapper<>();
		query.in(StkInventory::getMaterialId, ids);
		return list(query);
	}

	@Override
	@Async
	public boolean upDdFile(String id){
    	boolean flag=false;
		try {
			StkIoBill ioBill=stkIoBillService.getById(id);
			List<ZrkOrderProduct> productList = this.orderProductService.selectByMainId(ioBill.getId());
			ZrkShoporder zrkShoporder= shoporderService.selectByOrderCode(ioBill.getSourceNo());
			PrintOrderVO orderList =zrkDeliverEntryService.DdIoBillPrint(ioBill.getId());
			String srcFilePath="";
			srcFilePath = "/home/heckerstone/demo/qych.xlsx";
//			if(StringUtils.isNotBlank(zrkShoporder.getIsPrintMoney())
//					&&zrkShoporder.getIsPrintMoney().equals("0")) {
//				srcFilePath = "/home/heckerstone/demo/qychmq.xlsx";
//			}else{
//				srcFilePath = "/home/heckerstone/demo/qych.xlsx";
//			}
			String destFilePath = "/tmp/"+new Date().getTime()+".xls";
			Long pdfTime=new Date().getTime();
			String destFilePdfPath = "/www/wwwroot/erpqy.wfjstrong.com/img/"+pdfTime+".png";
			Map<String, PrintOrderVO> beanParams = new HashMap<String, PrintOrderVO>();
			beanParams.put("OrderList", orderList);
			XLSTransformer former = new XLSTransformer();
			former.transformXLS(srcFilePath, beanParams, destFilePath);
			Workbook wb = new Workbook();
			wb.loadFromFile(destFilePath);
            Worksheet sheet = wb.getWorksheets().get(0);
            sheet.saveToImage(destFilePdfPath);
//			wb.saveToFile(destFilePdfPath, FileFormat.PDF);
//			File file = new File(destFilePdfPath);
//			InputStream fis = new FileInputStream(file);
//			byte[] fileByte = FileCopyUtils.copyToByteArray(fis);
//			Base64.Encoder encoder = Base64.getEncoder();
			filePrint.fileUrlPrint(PrinterEnum.CFP535, FileTypeEnum.Image,"http://erp.wfqiyuan.com/img/"+pdfTime+".png",93);
//			String media= DingMessageUtils.sendDdUpFilew(destFilePdfPath);
//			String  user=userService.getUserThirdId(userIds);
//			if(StringUtils.isNotBlank(user)){
//					flag=DingMessageUtils.sendDingMessageByType(user,pdfTime+".pdf",media);
//			}else{
//				System.out.println("没有找到员工的第三方ID");
//			}
			return flag;
		}catch (Exception e){
			e.printStackTrace();
			System.out.println("失败"+e.getMessage());
		}

    	return flag;
	}
	
	@Override
	@Async
	public boolean upDdFile(String id, HashSet<String> orderIdSet) {
    	boolean flag=false;
		try {
			StkIoBill ioBill=stkIoBillService.getById(id);
			String orderId = null;
			ZrkShoporder zrkShoporder = null;
			if(CollUtil.isNotEmpty(orderIdSet)) {
				for (String shopOrderId : orderIdSet) {
					ZrkShoporder shoporder = this.shoporderService.getById(shopOrderId);
					if(null != shoporder) {
						zrkShoporder = shoporder;
						orderId = shopOrderId;
						break;
					}
				}
			}
			List<ZrkOrderProduct> productList = this.orderProductService.selectByMainId(orderId);
			PrintOrderVO orderList =zrkDeliverEntryService.DdIoBillPrint(ioBill.getId(), orderId);
			String srcFilePath="";
			srcFilePath = "/home/heckerstone/demo/qych.xlsx";
			if(null != zrkShoporder && 
					StringUtils.isNotBlank(zrkShoporder.getIsPrintMoney())
					&&zrkShoporder.getIsPrintMoney().equals("0")) {
				srcFilePath = "/home/heckerstone/demo/qychmq.xlsx";
			}else{
				srcFilePath = "/home/heckerstone/demo/qych.xlsx";
			}
			String destFilePath = "/tmp/"+new Date().getTime()+".xls";
			Long pdfTime=new Date().getTime();
			String destFilePdfPath = "/www/wwwroot/erpqy.wfjstrong.com/img/"+pdfTime+".png";
			Map<String, PrintOrderVO> beanParams = new HashMap<String, PrintOrderVO>();
			beanParams.put("OrderList", orderList);
			XLSTransformer former = new XLSTransformer();
			former.transformXLS(srcFilePath, beanParams, destFilePath);
			Workbook wb = new Workbook();
			wb.loadFromFile(destFilePath);
            Worksheet sheet = wb.getWorksheets().get(0);
            sheet.saveToImage(destFilePdfPath);
			filePrint.fileUrlPrint(PrinterEnum.CFP535, FileTypeEnum.Image,"http://erp.wfqiyuan.com/img/"+pdfTime+".png",93);
			return flag;
		}catch (Exception e){
			e.printStackTrace();
			System.out.println("失败"+e.getMessage());
		}

    	return flag;
	}

	@Override
	public Page<StkInventory> getInventory(IPage<StkInventory> page, List<String> ids, String warehouseId, String supplierId,
			String isClosed, String batchNoBegin, String batchNoEnd, String createTime) {
		return baseMapper.getInventory(page, ids, warehouseId, supplierId, isClosed, batchNoBegin, batchNoEnd, createTime);
	}

	@Override
	public int countHasInventoryMateiral(List<String> materialIds) {
		return baseMapper.countHasInventoryMateiral(materialIds);
	}
}
